package operations;

import book.Book;
import book.Booklist;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 */
public class AddOperation implements IOperation{
    public void work (Booklist booklist){
        //增添图书
        System.out.println("增加图书！");

        Scanner scanner = new Scanner(System.in);

        System.out.print("请输入图书的名字：");
        String name = scanner.nextLine();

        System.out.print("请输入图书的作者：");
        String author = scanner.nextLine();

        System.out.print("请输入图书的类型：");
        String type = scanner.nextLine();

        System.out.print("请输入图书的价格：");
        int prince = scanner.nextInt();

        //获取当前位置
        int currentSize = booklist.getUsedSize();

        //直接新创建一个 Book 类型的书，用作实参传递
        Book book = new Book(name,author,prince,type);

        booklist.setBooks(book,currentSize);

        //数量+1
        booklist.setUsedSize(currentSize + 1);

        System.out.println("增加成功！");
    }
}
